package com.cskaoyan.controller.extendController.weixin;

import com.cskaoyan.exception.CouponEmptyException;
import com.cskaoyan.exception.CouponReceiveException;
import com.cskaoyan.model.bean.Coupon;
import com.cskaoyan.model.bo.WXLoginBo;
import com.cskaoyan.model.bo.extend.WXCouponBo;
import com.cskaoyan.model.bo.extend.WXCouponReceiveBo;
import com.cskaoyan.model.bo.extend.WXCouponSelectBo;
import com.cskaoyan.model.bo.extend.WXExchangeBo;
import com.cskaoyan.model.vo.extend.BaseRespVo;
import com.cskaoyan.model.vo.extend.WXCouponVo;
import com.cskaoyan.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author：Chunk
 * @Description:
 * @Date Created in 17:49 2021/4/12
 */
@RestController
@RequestMapping("/wx/coupon")
public class WXCouponController {
    @Autowired
    CouponService couponService;

    @RequestMapping("list")
    public BaseRespVo wxCouponList(WXCouponBo wxCouponBo){
        WXCouponVo wxCouponVo = couponService.queryWXCouponList(wxCouponBo);
        return BaseRespVo.ok(wxCouponVo);
    }
    @RequestMapping("mylist")
    public BaseRespVo wxCouponMylist(WXCouponBo wxCouponBo){
        WXCouponVo wxCouponVo = couponService.queryWXMyCouponList(wxCouponBo);
        return BaseRespVo.ok(wxCouponVo);
    }
    @RequestMapping("selectlist")
    public BaseRespVo wxCouponSelectList(WXCouponSelectBo wxCouponSelectBo){
        List<Coupon> coupons = couponService.selectWXCouponList(wxCouponSelectBo);
        return BaseRespVo.ok(coupons);
    }
    @RequestMapping("receive")
    public BaseRespVo wxCouponReceive(@RequestBody WXCouponReceiveBo wxCouponReceiveBo) throws CouponReceiveException, CouponEmptyException {
        couponService.receiveWXCoupon(wxCouponReceiveBo.getCouponId());
        return BaseRespVo.ok();
    }
    @RequestMapping("exchange")
    public BaseRespVo wxCouponExchange(@RequestBody WXExchangeBo wxExchangeBo) throws CouponReceiveException, CouponEmptyException {
        couponService.exchangeWXCoupon(wxExchangeBo.getCode());
        return BaseRespVo.ok();
    }

}
